import style from '../../../src/assets/style/global.scss'

import { listMixin } from './list'
import { previewMixin } from './preview'
let pagingHeight = 50 // 默认分页器高度
try {
  if (style && style.pagingHeight) {
    pagingHeight = parseInt(style.pagingHeight) || 0
  }
} catch (e) {}

export const mainMixin = {
  data() {
    return {
      tableHeight: 580
    }
  },

  methods: {
    // 储存搜索字段
    setPathParams(origin = {}) {
      const { path, query: sourceSoltQuery } = this.$route
      const query = {}
      for (let key in origin) {
        if (origin[key]) query[key] = origin[key]
      }
      if (query.pageIndex <= 1) delete query.pageIndex
      delete query.pageSize
      this.$router
        .replace({
          path,
          query: {
            ...sourceSoltQuery,
            ...query
          }
        })
        .catch(() => {})
    }
  },

  mounted() {
    const el = this.$el
    if (!el || !el.querySelector) return
    const ref = el.querySelector('.main-body')
    if (!ref) return
    const windowHeight = window.document.documentElement.clientHeight
    console.log(windowHeight)
    // console.log('--------------')
    // console.log('el:')
    // console.dir(el)
    // console.log('elH:', el.offsetTop)
    // console.log('mainBody:')
    // console.dir(ref)
    // console.log('filter', el.querySelector('.filter').offsetHeight)
    // console.log('mainBodyOffset:', ref.offsetTop)
    // console.log('mainBodyHeight:', ref.height)
    // console.log('windowHeight:', windowHeight)
    // console.dir('outWindowObj:', window.parent.document.documentElement)
    // console.dir('innnerWindowObj:', window.document.documentElement)
    // console.log('--------------')
    this.tableHeight = windowHeight - (ref.offsetTop - el.offsetTop) - pagingHeight - 60 - 32 // 表头60 - main-body上下margin
  }
}

export { listMixin, previewMixin }
